﻿using Autodesk.Revit.Creation;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.ExtensibleStorage;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace revitDemo
{
    public class 螺旋 : RevietBase
    {
        public 螺旋(ExternalCommandData commandData) : base(commandData)
        {
        }


        public override void Test()
        {

            var pit = 2;
            var n = 2;

            var solids_T = new List<GeometryObject>();
            var options = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId);

            Arc arc1 = Arc.Create(XYZ.Zero, 0.5, 0, Math.PI, XYZ.BasisX, XYZ.BasisY);
            Arc arc2 = Arc.Create(XYZ.Zero, 0.5, Math.PI, 2 * Math.PI, XYZ.BasisX, XYZ.BasisY);
            CurveLoop circle = new CurveLoop();
            circle.Append(arc1);
            circle.Append(arc2);

            for (int i = 0; i < 20; i++)
            {
                var helix = CylindricalHelix.Create(new XYZ(0, n, 0), 3, XYZ.BasisX, XYZ.BasisY, pit, 0, Math.PI);
                var loops = new List<CurveLoop>();
                for (int j = 0; j <= 10; j++)
                {
                    var transform = TransformUtils.GetTransformVertical(helix, (double)j / 10);
                    loops.Add(CurveLoop.CreateViaTransform(circle, transform));
                }
                var s1 = GeometryCreationUtilities.CreateLoftGeometry(loops, options);
                helix = CylindricalHelix.Create(new XYZ(0, n, 0), 3, XYZ.BasisX, XYZ.BasisY, pit, Math.PI, 2 * Math.PI);
                loops = new List<CurveLoop>();
                for (int j = 0; j <= 10; j++)
                {
                    var transform = TransformUtils.GetTransformVertical(helix, (double)j / 10);
                    loops.Add(CurveLoop.CreateViaTransform(circle, transform));
                }
                var s2 = GeometryCreationUtilities.CreateLoftGeometry(loops, new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId));

                solids_T.Add(s1);
                solids_T.Add(s2);
                n += pit;
            }

            OpenTransaction("22", x =>
            {
                var directshape = DirectShape.CreateElement(Doc, Category.GetCategory(Doc, BuiltInCategory.OST_GenericModel).Id);
              
                directshape.AppendShape(solids_T);


            });


        }




    }
}
